package exception;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FinallyDemo3 {
    public static void main(String[] args) {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("fos.dat");
            fos.write(3);
        } catch (IOException e) {
            System.out.println("出错了");
        } finally {
            try {
                if (fos != null) {//判断是否存在文件，例如在没有G盘却关闭里面的文件
                    fos.close();
                }
            } catch (IOException e) {
                System.out.println("关闭出错");
            }
        }

    }
}
